<template>
  <div class="form-add">
    <p>营业人姓名：</p>
    <input type="text" placeholder="请输入营业人员姓名" v-model="userName" />
    <p>手机号码：</p>
    <input type="number" placeholder="请输入手机号码" v-model="phone" />
    <van-button type="info" block class="submit" @click="submit">提交</van-button>
  </div>
</template>
<script>
import { addShopUser } from '../service/service.js'
export default {
  name: 'shopAssistant-add',
  data () {
    return {
      userName: '',
      userId: '',
      phone: '',
      isAdd: true
    }
  },
  created () {
    this.isAdd = this.$route.query.isAdd === '1'
    if (!this.isAdd) {
      this.userName = this.$route.query.userName
      this.userId = this.$route.query.userId
      this.phone = this.$route.query.phone
    }
    console.log(this.isAdd)
  },
  methods: {
    submit () {
      const params = {
        opt: '', // 新增：add  修改：edit
        shopUserId: '', // 人员id （新增0，修改必传）
        userName: this.userName,
        phone: this.phone
      }
      if (this.isAdd) {
        params.opt = 'add'
        params.shopUserId = '0'
      } else {
        params.opt = 'edit'
        params.shopUserId = this.userId
      }
      addShopUser(params)
        .then((res) => {
          const data = res.data
          if (data.ret !== 0) {
            this.$toast(data.msg)
            return false
          }
          this.$toast(data.msg)
          this.$router.back()
        })
        .catch((err) => {
          console.log(err)
        })
    }
  }
}
</script>
<style lang="less" scoped>
.form-add {
  background: #fff;
  padding: 10px 15px 0;
  p {
    color: #666666;
    line-height: 40px;
  }
  input {
    width: 100%;
    height: 40px;
    line-height: 40px;
    background: #f2f6fb;
    border-radius: 4px;
    border: none;
    padding: 0 10px;

  }
  .submit {
    margin-top: 50px;
    border-radius: 5px;
  }
}
</style>
